<?php 
require_once('../utility/appConsts.php');
/**
 * ProductData class that stores product data to server
 * in product table
 * @author relsellglobal
 *
 */
class ProductData {
	
    function storeProductData($productType,$productQty,$userId) {
    	$appConstants = new appConstsClass();
    	$appConstants -> initialize();
    	$db_handle = mysql_connect($appConstants->SERVER, $appConstants->DBUSERNAME, $appConstants->DBPASSWORD);
    	$db_found = mysql_select_db($appConstants->DBNAME, $db_handle);
    	if ($db_found) { 
    		$SQL = "INSERT INTO product_table (product_type,product_quantity,userid) VALUES ('$productType',$productQty,$userId) ";
    		if ($appConstants->DEBUG) {
    		    echo $SQL."<br/>";
    		}
    		mysql_query($SQL);
    		$myerror = mysql_error();
    		$affectedRows = mysql_affected_rows();
    		if ($appConstants->DEBUG) {
    			echo $myerror."<br/>";
    			echo $affectedRows."<br/>";
    		}
    		return $affectedRows > 0 ? $affectedRows : -1 ;
    	}
    }
    function printTestProductData() {
    	$appConstants = new appConstsClass();
    	$appConstants -> initialize();
    	$arr = array();
    	$db_handle = mysql_connect($appConstants->SERVER, $appConstants->DBUSERNAME, $appConstants->DBPASSWORD);
    	$db_found = mysql_select_db($appConstants->DBNAME, $db_handle);
    	echo mysql_error();
    	if ($db_found) {
    		$SQL = "SELECT product_type,product_quantity,selling_date FROM product_table";
    		$result = mysql_query($SQL,$db_handle);
    		$total = mysql_num_rows($result);
    		if ($total > 0) {
    			while ( $db_field = mysql_fetch_assoc($result) ) {
    			echo json_encode($db_field);
    		    }
    		}
    	}
    	mysql_close($db_handle);
    }
}
?>